home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / nurbsSurfaceInformation.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  6.5 KB  |  240 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. proc int getNurbsSurfaceKnots( 
  18.     string $srfName, float $uKnots[], float $vKnots[] )
  19. //
  20. //    Description :
  21. //
  22. {
  23.  
  24.     // create info Node.
  25.     string $infoNode ;
  26.     if( catch( $infoNode = `createNode surfaceInfo` ) ) {
  27.         return 1; // failed
  28.     } 
  29.  
  30.     // connect surface on to the info node.
  31.     string $outAttr = $srfName + ".local" ; 
  32.     string $inAttr = $infoNode + ".is" ;
  33.     connectAttr $outAttr $inAttr ;
  34.  
  35.     // read the knots.
  36.     $uKnots = `getAttr ($infoNode + ".knotsU")`;    
  37.     $vKnots = `getAttr ($infoNode + ".knotsV")`;    
  38.  
  39.     // delete surface info node.
  40.     delete $infoNode ;
  41.  
  42.     // worked
  43.     return 0;
  44. }
  45.  
  46. global proc string printNurbsSurfaceMiscInfo(string $srf)
  47. // Description :
  48. //  returns the knot values in a string
  49. {
  50.     string $w;
  51.  
  52.     // form
  53.     int $formU = eval("getAttr " + $srf + ".formU");
  54.     int $formV = eval("getAttr " + $srf + ".formV");
  55.     $w = "Form along U, V: " + $formU + " " + $formV + " (0 = open, 1 = closed, 2 = periodic)\n";
  56.  
  57.     // degree
  58.     int $degreeU = eval("getAttr " + $srf + ".degreeU");
  59.     int $degreeV = eval("getAttr " + $srf + ".degreeV");
  60.     $w += "Degree along U, V: " + $degreeU + " " + $degreeV + "\n";
  61.     
  62.     // number of spans
  63.     int $nspansU = eval("getAttr " + $srf + ".spansU");
  64.     int $nspansV = eval("getAttr " + $srf + ".spansV");
  65.     $w += "Nspans along U, V: " + $nspansU + " " + $nspansV + "\n";
  66.     
  67.     // bounding box (what if it is 2d??)
  68.     float $minBox[] = eval("getAttr " + $srf + ".boundingBoxMin");
  69.     $w += "Bounding box min: " + $minBox[0] + " " + $minBox[1] + " " + $minBox[2];
  70.     $w += "\n";
  71.     
  72.     float $maxBox[] = eval("getAttr " + $srf + ".boundingBoxMax");
  73.     $w += "             max: " + $maxBox[0] + " " + $maxBox[1] + " " + $maxBox[2];
  74.     $w += "\n";
  75.  
  76.     return $w;
  77. }
  78.  
  79. global proc string printNurbsSurfaceKnots(string $srf)
  80. // Description :
  81. //  prints the knot values
  82. {
  83.     string $w;
  84.  
  85.     float $uKnots[];
  86.     float $vKnots[];
  87.     if(getNurbsSurfaceKnots($srf, $uKnots, $vKnots)) {
  88.         return 1; // failed
  89.     }
  90.  
  91.     $w = "Knots along U: ";
  92.     int $numKnots = size($uKnots);
  93.     for($i=0; $i<$numKnots; $i++) {
  94.         $w += " " + $uKnots[$i];
  95.     }
  96.     $w += "\n";
  97.  
  98.     $w += "Knots along V: ";
  99.     int $numKnots = size($vKnots);
  100.     for($i=0; $i<$numKnots; $i++) {
  101.         $w += " " + $vKnots[$i];
  102.     }
  103.     $w += "\n";
  104.     return $w;
  105. }
  106.  
  107. global proc string printNurbsSurfaceCVs(string $srf)
  108. // Description :
  109. //  prints the CV positions in world space
  110. {
  111.         
  112.     string $w;
  113.  
  114.     // create info Node.
  115.     string $infoNode = `createNode surfaceInfo`;
  116.     
  117.     // connect surface on to the info node.
  118.     string $outAttr = $srf + ".ws[0]" ;
  119.     string $inAttr = $infoNode + ".is" ;
  120.     connectAttr $outAttr $inAttr ;
  121.  
  122.     // get number of CVs in U and V (always degree+spans even
  123.     // for periodics since overlapping CVs are available separately)
  124.     int $degreeU = eval("getAttr " + $srf + ".degreeU");
  125.     int $nspansU = eval("getAttr " + $srf + ".spansU");
  126.     int $numCVsAlongU = $nspansU + $degreeU;
  127.  
  128.     int $degreeV = eval("getAttr " + $srf + ".degreeV");
  129.     int $nspansV = eval("getAttr " + $srf + ".spansV");
  130.     int $numCVsAlongV = $nspansV + $degreeV;
  131.  
  132.     // inform caller that
  133.     int $formU = eval("getAttr " + $srf + ".formU");
  134.     int $formV = eval("getAttr " + $srf + ".formV");
  135.     if($formU == 2 || $formV == 2) {
  136.         print "Note - surface is periodic. CV count and display will including overlapping ones along seam\n";
  137.     }
  138.  
  139.     $w = "Number of CVs in U, V: " + $numCVsAlongU + " " + $numCVsAlongV + "\n";
  140.     
  141.     // dimension of each CV
  142.     int $dim = 0;
  143.     if( size(`ls ($srf + ".cv[0][0]")`) > 0 ) {
  144.         $dim = size (eval("getAttr " + $srf + ".cv[0][0]"));
  145.         $w += "Dimension of surface: " + $dim + "\n";
  146.     } else {
  147.         $w += "Dimension of surface: No CVs, Dimension unknown\n";
  148.     }
  149.     
  150.     // Get the CV positions including overlapping ones
  151.     $w += "CVs in world space:\n";
  152.     int $numCV = -1;
  153.     for($i=0; $i<$numCVsAlongU; $i++) {
  154.         for($j=0; $j<$numCVsAlongV; $j++) {
  155.             $numCV++;
  156.             float $cvs[] = `getAttr ($infoNode + ".cp["+$numCV+"]")`;
  157.             $w += $i + " " + $j + ": ";
  158.             for($k=0; $k<$dim; $k++) {
  159.                 $w +=  $cvs[$k] + " ";
  160.             }
  161.             $w += "\n";
  162.         }
  163.     }
  164.     return $w;    
  165. }
  166.  
  167. global proc string getSurfaceInformation( string $srf )
  168. {
  169.     string $info;
  170.  
  171.     // get the form,degree,nspans,bbox
  172.     $info = printNurbsSurfaceMiscInfo($srf);
  173.  
  174.     // get the knots
  175.     $info += printNurbsSurfaceKnots($srf);
  176.  
  177.     // get the CVs
  178.     $info += printNurbsSurfaceCVs($srf);
  179.  
  180.     return $info;
  181. }
  182.  
  183. global proc string getSurfacesInformation( string $srf[] )
  184. {
  185.     string $info = "";
  186.     global int $gSelectNurbsSurfacesBit ;
  187.     string $srfList[] = `filterExpand -ex true
  188.             -sm $gSelectNurbsSurfacesBit $srf`;
  189.  
  190.     int $len = size($srfList) ;
  191.     if( $len == 0 ) {
  192.         return $info;
  193.     }
  194.  
  195.     for($srfNum = 0; $srfNum < $len; $srfNum++) {
  196.         $info += getSurfaceInformation( $srfList[$srfNum] );
  197.     }
  198.     return $info;
  199. }
  200.  
  201. global proc nurbsSurfaceInformation()
  202. {
  203.     string $w; // for messages
  204.  
  205.     // Get the select list.
  206.     string $selList[] = `ls -sl`;
  207.  
  208.     // Run filter to select only the NURBS surfaces
  209.     global int $gSelectNurbsSurfacesBit ;
  210.  
  211.     string $srfList[] = `filterExpand -ex true 
  212.         -sm $gSelectNurbsSurfacesBit`;
  213.     int $len = size($srfList) ;
  214.     if( $len == 0 ) {
  215.         print "No NURBS surfaces selected\n" ;
  216.         return;
  217.     }
  218.  
  219.     // Work on the last item if more than one NURBS surface in list.
  220.     for($srfNum = 0; $srfNum < $len; $srfNum++) {
  221.         string $srf = $srfList[$srfNum] ;
  222.  
  223.         // print separator if more than one surface
  224.         if($len>1) print "----------------------------------\n";
  225.  
  226.         // surface name
  227.         $w = "Surface: " + $srf + "\n";
  228.         print $w;
  229.  
  230.         string $info = getSurfaceInformation( $srf );
  231.         print $info;
  232.     }
  233.  
  234.     // print separator if more than one surface
  235.     if($len>1) print "----------------------------------\n";
  236.  
  237.     // reselect surface for which information was returned
  238.     select -r $selList;
  239. }
  240.